package com.svo.weitu.util;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;

public class QuitPopAd {

	private static Dialog dialog;
	
	private static QuitPopAd quitPopAd;
	
	public static QuitPopAd getInstance(){
		if(quitPopAd == null){
			quitPopAd = new QuitPopAd();
		}
		return quitPopAd;
	}
	
	/**
	 * 展示退屏广告
	 * @param context
	 */
	public void show(final Context context){
		
		dialog = new Dialog(context, android.R.style.Theme_Translucent_NoTitleBar);//第二个样式参数,可根据自己应用或游戏中的布局进行设置
		// 判断插屏广告是否已初始化完成，用于确定是否能成功调用插屏广告
			new AlertDialog.Builder(context)
			.setTitle("退出提示")
			.setMessage("确定要退出当前应用吗？")
			.setPositiveButton("确定", new AlertDialog.OnClickListener(){
				@Override
				public void onClick(DialogInterface dialog, int which) {
					if(dialog != null){
						dialog.cancel();
					}
					((Activity)context).finish();
				}
			})
			.setNegativeButton("取消", new AlertDialog.OnClickListener(){
				@Override
				public void onClick(DialogInterface dialog, int which) {
					dialog.cancel();
				}
			})
			.create().show();
	}
	
	/**
	 * 关闭退屏广告对话框
	 */
	public void close(){
		if(dialog != null && dialog.isShowing()){
			dialog.cancel();
		}
	}
	
	
}
